package com.example.blew.demo.Controller;

import com.example.blew.demo.model.TablePo;
import com.example.blew.demo.model.User;
import com.example.blew.demo.service.impl.WorkServiceImpl;
import com.example.blew.demo.uitl.RrturnMesage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author chaodong.zeng@pcitc.com
 * @since 2022/9/6
 */

@RestController
@RequestMapping("pms")
@Api(tags = "Work", value = "")
public class WorkController {

    @Resource
    WorkServiceImpl workServers;

    @GetMapping("userInfo")
    @ApiOperation(value = "获取用户列表")
    public RrturnMesage getUser(int current, int size) {

        return workServers.select(current, size);
    }

    @GetMapping("users")
    @ApiOperation(value = "条件获取用户列表")
    public RrturnMesage userInfo(int current, int size, String name, int status) {

        return workServers.conditionSelect(current, size,name,status);
    }

    @PostMapping("user")
    @ApiOperation(value = "添加用户")
    public RrturnMesage insertUser(@RequestBody User user) {
        boolean b = workServers.insertUser(user);
        if (b) {
            return RrturnMesage.ok();
        } else {
            return RrturnMesage.error();
        }
    }

    @GetMapping("deleteUserById")
    @ApiOperation(value = "根据id删除用户")
    public RrturnMesage deletUser(int id) {
        boolean b = workServers.deletUser(id);
        if (b) {
            return RrturnMesage.ok();
        } else {
            return RrturnMesage.error();
        }
    }

    @PostMapping("updateUser")
    @ApiOperation(value = "修改用户")
    public RrturnMesage updateUser(@RequestBody User user) {
        boolean b = workServers.updateUser(user);
        if (b) {
            return RrturnMesage.ok();
        } else {
            return RrturnMesage.error();
        }
    }


    @GetMapping("getUserDetail")
    @ApiOperation(value = "查询具体用户详情")
    public RrturnMesage updateUser(int id) {
        User user= workServers.getUser(id);
        return RrturnMesage.ok().data("user",user);
    }

    @PostMapping("test")
    @ApiOperation(value = "前端接口传对象测试")
    public RrturnMesage test(@RequestBody TablePo tablePo){
        tablePo.getAddress();

        return null;
    }


}